package com.ossjk.oa.paid.service.impl;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.ossjk.oa.paid.entity.Paid;
import com.ossjk.oa.paid.mapper.PaidMapper;
import com.ossjk.oa.paid.service.IPaidService;
import com.ossjk.oa.paid.vo.PaidVo;

/**
 * 服务实现类
 * 
 * @Author Datou
 * @Version 1.0, 2020-05-14
 * @See
 * @Since com.ossjk.oa.accounting.service.impl
 * @Description: TODO
 */
@Service
public class PaidServiceImpl extends ServiceImpl<PaidMapper, Paid> implements IPaidService {

	@Autowired
	private IPaidService iPaidService;

	@Override
	public Page selectVoPage(Page page, Wrapper wrapper) {
		SqlHelper.fillWrapper(page, wrapper);
		page.setRecords(baseMapper.selectVoPage(page, wrapper));
		return page;
	}

	@Override
	public boolean insertBatchPaids(List<Paid> paids) {
		for (Paid paid : paids) {
			Date date = paid.getDate();
			String eid = paid.getEid();
			Wrapper wrapper = Condition.create().eq("eid", eid).eq("date", date);
			// 删除已有的工资信息
			iPaidService.delete(wrapper);
		}
		return iPaidService.insertBatch(paids);
	}

	@Override
	public PaidVo selectVo(Wrapper wrapper) {
		// TODO Auto-generated method stub
		return baseMapper.selectVo(wrapper);
	}

}
